
package org.hive.animation
{
	import fl.motion.Motion;
	import fl.motion.Source;
	import flash.display.*;
	
	public class SourceTranslation
    {
        /**
        *
        */
		private var __source:Source;

        /**
        *
        */
		private var __motionXML:XML;
		
        /**
        *
        * @param	motion
        */
		public function SourceTranslation( motion:XML )
		{
			__motionXML = motion;
			__source = new Motion( motion ).source;
		}
		
        /**
        *
        * @return
        */
		public function recreate( ):DisplayObject
		{
			var sourceObject:MovieClip = new MovieClip();
			sourceObject.graphics.beginFill( 0x00 );
			sourceObject.graphics.drawRect( 0, 0, __source.dimensions.width, __source.dimensions.height );
			
			sourceObject.scaleX = scaleX;
			sourceObject.scaleY = scaleY;
			
			sourceObject.rotation = rotation;
			
			sourceObject.x = getPoint( __source.dimensions.width, __source.transformationPoint.x, x );
			sourceObject.y = getPoint( __source.dimensions.height, __source.transformationPoint.y, y );
			
			return sourceObject;
		}
		
        /**
        *
        * @return
        */
		public function get symbolName( ):String
		{
			return __source.symbolName;
		}
		
        /**
        *
        * @return
        */
		public function get rotation( ):Number
		{
			return __motionXML.children()[0].children().@rotation;
		}
		
        /**
        *
        * @return
        */
		public function get scaleX( ):Number
		{
			return __motionXML.children()[0].children().@scaleX;
		}
		
        /**
        *
        * @return
        */
		public function get scaleY( ):Number
		{
			return __motionXML.children()[0].children().@scaleY;
		}
		
        /**
        *
        * @return
        */
		public function get x( ):Number
		{
			return  __motionXML.children()[0].children().@x;
		}
		
        /**
        *
        * @return
        */
		public function get y( ):Number
		{
			return  __motionXML.children()[0].children().@y;
		}
		
        /**
        *
        * @param	size
        * @param	transform
        * @param	source
        * @return
        */
		private function getPoint( size:Number, transform:Number, source:Number ):Number
		{
			var p:Number = size * transform;
			
			if( p < 0 && source > 0 ){
				return p - source;
			}
			else return source - p;
		}
	}
}
